home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-10-15 | 25.1 KB | 870 lines | [TEXT/MPS ] |
- /*
- * File: Request.cp
- *
- * Contains: xxx put contents here xxx
- *
- * Written by: Rick Violet
- *
- * Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
- *
- * Change History (most recent first):
- *
- * 11/18/92 RV xxx put comment here xxx
- * 06/19/94 SBR Added ExtractValueFromNthParam methods
- * 09/11/94 SBR Added ExtractValueFromNthParam for Boolean
- *
- * To Do:
- */
-
- #ifndef __Request__
- #include "Request.h"
- #endif
-
- #ifndef __RequestDispatcher__
- #include "RequestDispatcher.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- /*SBR Hacked these in 05/24/94*/
- /*
- #ifndef __STREAM__
- #include "Stream.h"
- #endif
- */
-
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Global Variables
- //—————————————————————————————————————————————————————————————————————————————————————
- extern RequestDispatcher* gTheRequestDispatcher;
- extern ThreadID gRequestDispatcherThreadID;
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::Request - constructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- Request::Request()
- {
- fWhichService = nil; //———— No Request name yet
- fParamList = nil; //———— create empty list of parameters
- fReturnValue = nil; //———— create empty return value
- fErrorCode = noErr; //———— No errors yet
- fErrorMessage = nil; //———— No error message yet
- fCanceled = false; //———— Not canceled yet
- fRequestIdentifier = 0; //———— No identifier yet
-
- /*SBR Hacked this in 10/16/94 */
- fThreadID = kNoThreadID; //———— No thread has been assigned yet
- fThreadOptions = 0; //———— No thread options have been assigned yet
- fService = nil; //———— No service has been assigned
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::~Request - destructor.
- //—————————————————————————————————————————————————————————————————————————————————————
- Request::~Request()
- {
- //———— dispose of fWhichService
- if( fWhichService != nil )
- {
- delete fWhichService;
- }
-
- //———— dispose of fParamList
- if( fParamList != nil )
- {
- delete fParamList;
- }
-
- //———— dispose of fReturnValue
- if( fReturnValue != nil )
- {
- delete fReturnValue;
- }
-
- //———— dispose of fErrorMessage
- if( fErrorMessage != nil )
- {
- delete fErrorMessage;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::Initialize - initialize the Request
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::Initialize()
- {
- //———— Tell V.U. not to time out for at least kDefaultTimeOutSeconds
- ResetTimeOutCounter();
-
- return noErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::HasBeenCanceled - Check to see if this command has been canceled
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Request::HasBeenCanceled()
- {
- return fCanceled;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ResetTimeOutCounter - inform V.U. to not let this Request time out
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::ResetTimeOutCounter( unsigned long pNewTimeOutInterval )
- {
- //———— Set up the Time Manager task to fire again at a later time
- if( !HasBeenCanceled() )
- {
- //———— Keep Track of when we'll time out
- fSendResetTicks = TickCount() + (pNewTimeOutInterval * 60);
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::IsACancelRequest - Is this a Cancel Request?
- // return true if this is a cancel service request
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Request::IsACancelRequest()
- {
- if( relstring( fWhichService, (char*)kVUAECancelService, false, true ) == 0 )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::IsCancelRequestForThisRequest - is the cancel request
- // passed in as a parameter for canceling this sevice request object
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Request::IsCancelRequestForThisRequest( Request* pCancelReq )
- {
- long tReqID;
-
- //———— Get the Identifier of the request to cancel
- //———— from the Cancel Request object
- tReqID = pCancelReq->GetIdentifierOfRequesttoCancel();
- if( tReqID == fRequestIdentifier )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /*SBR Hacked this in 10/16/94 */
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::CancelThisRequest - cancel this request
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::CancelThisRequest( )
- {
- ThreadID tReqThreadID;
- ThreadState tReqThreadState;
- OSErr tErr;
-
- fCanceled = true;
-
- if( this->IsThreaded() )
- {
- //———— See if the request being canceled is in a stopped thread. If it is,
- //———— set its state to Ready so it gets time to recognize the cancel.
- tReqThreadID = this->GetThreadID();
-
- tErr = GetThreadState( tReqThreadID, &tReqThreadState );
- if( tErr != noErr )
- {
- DebugStr( "\pRequest::CancelThisRequest- error from GetThreadState" );
- return;
- }
-
- if( tReqThreadState == kStoppedThreadState )
- {
- tErr = SetThreadState( tReqThreadID, kReadyThreadState, kNoThreadID );
- if( tErr != noErr )
- {
- DebugStr( "\pRequest::CancelThisRequest- error from SetThreadState" );
- return;
- }
- }
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::IsThreaded - Is this Request executing in a different thread?
- //—————————————————————————————————————————————————————————————————————————————————————
- Boolean
- Request::IsThreaded()
- {
- //———— gRequestDispatcherThreadID could be kNoThreadID if app is non-threaded
- //———— commented this out to support non-threaded services executed in a
- //———— separate thread from the RequestDispatcher or Application thread
- return !(( fThreadID == kNoThreadID ) || ( fThreadID == gRequestDispatcherThreadID ));
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetErrorCode - set the Error code for this request
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetErrorCode( OSErr tErr )
- {
- fErrorCode = tErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetErrorMessage - set the Error message for this request
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetErrorMessage( char* tErrText )
- {
- //———— Keep Request status in sync with the error code
- fErrorMessage = new char[ strlen( tErrText ) + 1];
- if( fErrorMessage )
- {
- strcpy( fErrorMessage, tErrText );
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::GetNthParam - get the Nth parameter
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::GetNthParam( short pIndex, ScriptValuePtr& pValue, ValueKind& pVKind )
- {
- if( fParamList != nil )
- {
- return fParamList->GetNthItem( pIndex, pValue, pVKind );
- }
- else
- {
- pVKind = kVUAnyKind;
- pValue = nil;
- return errAEWrongParameters;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::GetParamCount - return the number of parameters
- //—————————————————————————————————————————————————————————————————————————————————————
- short
- Request::GetParamCount()
- {
- if( fParamList != nil )
- {
- return fParamList->GetCount();
- }
- else
- {
- return 0;
- }
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a Number ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( short pNumber )
- {
- ScriptValue* tVal;
-
- tVal = new VUNumber( pNumber );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a Number ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( long pLongNumber )
- {
- ScriptValue* tVal;
-
- tVal = new VULongNumber( pLongNumber );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a Boolean ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( Boolean pFlag )
- {
- ScriptValue* tVal;
-
- tVal = new VUBoolean( pFlag );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a String ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( char* pString )
- {
- ScriptValue* tVal;
-
- tVal = new VUString( pString );
- fReturnValue = tVal;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a List ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetReturnValue( ScriptValuePtr pScriptValue )
- {
- // fReturnValue = pScriptValue;
- fReturnValue = pScriptValue->Clone();
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::SetReturnValue - set the return value for this request
- // to a String ScriptValue
- //—————————————————————————————————————————————————————————————————————————————————————
- void
- Request::SetWhichService( char* pServiceText )
- {
- fWhichService = new char[ strlen( pServiceText ) + 1 ];
- if( fWhichService == nil )
- {
- SetErrorCode( memFullErr );
- SetErrorMessage( "Failed to allocate string for Request object." );
- }
- else
- {
- strcpy( fWhichService, pServiceText );
- }
- }
-
- //#######################################################################
- //#######################################################################
- // The following overloaded request methods were added by Stuart Russell.
- // Search for 'ExtractValueFromNthParam' to find changes to services.
- //#######################################################################
- //#######################################################################
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a short from integer/string parameters
- // VU 2.0.1 sends numbers to tools as shorts; VU 2.1 sends them as longs.
- // This method stores integers or strings into a short variable.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, short* pShortPtr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a long first (VU 2.1)
- case kVULongNumberKind:
- {
- *pShortPtr = (short)((VULongNumber*)tParam)->GetNumber();
- }
- break;
-
- //———— try a short next (VU 2.0.1)
- case kVUNumberKind:
- {
- *pShortPtr = ((VUNumber*)tParam)->GetNumber();
- }
- break;
-
- //———— try a string as a last resort
- case kVUStringKind:
- {
- long tempLong;
-
- stringtonum( ((VUString*)tParam)->GetText(), &tempLong );
- *pShortPtr = (short)tempLong;
- }
- break;
-
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be an integer or string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be an integer or string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a long from integer/string parameters
- // VU 2.0.1 sends numbers to tools as shorts; VU 2.1 sends them as longs.
- // This method stores integers or strings into a long variable.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, long* pLongPtr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a long first (VU 2.1)
- case kVULongNumberKind:
- {
- *pLongPtr = ((VULongNumber*)tParam)->GetNumber();
- }
- break;
-
- //———— try a short next (VU 2.0.1)
- case kVUNumberKind:
- {
- *pLongPtr = (long)((VUNumber*)tParam)->GetNumber();
- }
- break;
-
- //———— try a string as a last resort
- case kVUStringKind:
- {
- long tempLong;
-
- stringtonum( ((VUString*)tParam)->GetText(), &tempLong );
- *pLongPtr = tempLong;
- }
- break;
-
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be an integer or string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be an integer or string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a char[] from a string parameter
- // This method copies a C string to the place pointed to by a char*.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, char *pCharPtr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a string
- case kVUStringKind:
- {
- strcpy( pCharPtr, ((VUString*)tParam)->GetText() );
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a CStr255 from a string parameter
- // This method copies a C string into a CStr255. Conversion is automatic.
- // Note: a CStr255 is physically a Pascal string - see PascalString.cp.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, CStr255* pCStr255Ptr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a string
- case kVUStringKind:
- {
- /* overloaded operator = converts it to a Pascal string */
- *pCStr255Ptr = ((VUString*)tParam)->GetText();
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a CStr63 from a string parameter
- // This method copies a C string into a CStr63. Conversion is automatic.
- // Note: a CStr63 is physically a Pascal string - see PascalString.cp.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, CStr63* pCStr63Ptr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a string
- case kVUStringKind:
- {
- /* overloaded operator = converts it to a Pascal string */
- *pCStr63Ptr = ((VUString*)tParam)->GetText();
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a CStr32 from a string parameter
- // This method copies a C string into a CStr32. Conversion is automatic.
- // Note: a CStr32 is physically a Pascal string - see PascalString.cp.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, CStr32* pCStr32Ptr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a string
- case kVUStringKind:
- {
- /* overloaded operator = converts it to a Pascal string */
- *pCStr32Ptr = ((VUString*)tParam)->GetText();
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a CStr31 from a string parameter
- // This method copies a C string into a CStr31. Conversion is automatic.
- // Note: a CStr31 is physically a Pascal string - see PascalString.cp.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, CStr31* pCStr31Ptr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a string
- case kVUStringKind:
- {
- /* overloaded operator = converts it to a Pascal string */
- *pCStr31Ptr = ((VUString*)tParam)->GetText();
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a ScriptValue* from a string parameter.
- // This method stores a ScriptValue* into a ScriptValue* variable. No
- // copying occurs. The pScriptValuePtrPtr will point to a member of an item
- // in a VUList in the request object. This VUList will be deleted as soon as
- // your service's ProcessRequest() method returns, so you should extract the
- // contents ASAP if you want to keep them.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, ScriptValue** pScriptValuePtrPtr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try any kind
- case kVUListKind:
- {
- *pScriptValuePtrPtr = ((ScriptValue*)tParam);
- //*pScriptValuePtrPtr = (ScriptValue*)(tParam->Clone());
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a ScriptValue.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a ScriptValue." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a char* from a string parameter
- // This method stores a char* into a char* variable. No copying occurs.
- // The pCharPtr will point to a member of an item in a VUList, which may
- // be deleted at any time, so you should extract the contents ASAP.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, char** pCharPtrPtr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— try a string
- case kVUStringKind:
- {
- *pCharPtrPtr = ((VUString*)tParam)->GetText();
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a string." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Request::ExtractValueFromNthParam - Assign a Boolean from a Boolean parameter
- // This method stores a Boolean into a Boolean variable.
- //—————————————————————————————————————————————————————————————————————————————————————
- OSErr
- Request::ExtractValueFromNthParam( short pIndex, Boolean* pBooleanPtr )
- {
- OSErr tErr;
- ScriptValue* tParam;
- ValueKind tKind;
-
- //———— Specify any kind of VUValue at first
- //———— GetNthParam sets tKind to the actual kind of tParam returned
- tKind = kVUAnyKind;
- tErr = this->GetNthParam( pIndex, tParam, tKind );
-
- if ( tErr != noErr ) {
- this->SetErrorCode( tErr );
- // this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
- this->SetErrorMessage( "Failed to extract a parameter" );
- return tErr;
- }
-
- switch (tKind)
- {
- //———— we want a Boolean
- case kVUBooleanKind:
- {
- *pBooleanPtr = ((VUBoolean*)tParam)->GetBoolean();
- }
- break;
-
- default:
- {
- this->SetErrorCode( paramErr );
- // this->SetErrorMessage( form("Error: parameter %d must be a Boolean.",pIndex) );
- this->SetErrorMessage( "Error: parameter must be a Boolean." );
- return paramErr;
- }
- }
-
- return noErr;
- }
-